import React, { Component } from "react";
import "antd/dist/antd.css";
// import './Comment.scss';
import axios from "axios";
// -----------------------------------------
import CommentList from "./commentList";
import CommentSub from "./commentSub";
// -----------------------------------------

class Comment extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dataList: []
    };
    this.init();
  }
  init() {
    this.seGetList();
  }
  seGetList() {
    axios.get("http://127.0.0.1:2333/").then(res => {
      console.log(res);
      this.setState({ dataList: res.data });
    });
  }
  seSubItem(value, date) {
    axios
      .post("http://127.0.0.1:2333/submit/", {
        author: "visiter",
        content: value,
        datetime: new Date()
      })
      .then(res => {
        console.log(res);
        if (res.data === "success") this.seGetList();
      });
  }
  render() {
    return (
      <div className="Comment" style={{ padding: "10px" }}>
        <CommentList content={this.state.dataList} />
        <CommentSub subItem={this.seSubItem.bind(this)} />
      </div>
    );
  }
}
export default Comment;

// -----------------------------------------
// --creatByBrown--
// ----
